// component/categorybar/categorybar.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    param: {
      type: Object,
    },
    api_host: {
      type: String
    },
    wxapp_img: {
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    pitchOn: 0,
    scroll: 'current0',
    list: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    clickChange(e) {
      this.setData({
        pitchOn: e.target.dataset.index,
        scroll: 'current' + (e.target.dataset.index-1)
      })
    },
    onClickCat: function () {
      wx.switchTab({
        url: '/pages/cat/cat',
      })
    },
    onClick: function (e) {
      var o = e.currentTarget.dataset.open_type;
      if ("tel" == o) {
        var n = e.currentTarget.dataset.tel;
        getApp().core.makePhoneCall({
          phoneNumber: n
        });
      } else {
        var url = e.currentTarget.dataset.url;
        if (url.indexOf('pages/index/index') >= 0 ||
        url.indexOf('pages/cat/cat') >= 0 ||
        url.indexOf('pages/cart/cart') >= 0 ||
        url.indexOf('pages/posts/index') >= 0 ||
        url.indexOf('pages/user/user') >= 0
        ) {
            wx.switchTab({ url })
        } else {
          wx.navigateTo({
            url: url,
          })
        }
      }
      return !1;
    }
  },
  lifetimes: {
    attached: function () {
      var list = this.data.param.list
      list.unshift({
        name: '首页',
        open_type: 'navigate',
        url: '/pages/index/index',
        appid: '',
        path: '',
        page_name: '商城首页'
      })
      this.setData({
        list: list
      })
    }
  }
})